package com.goodmean.teacher.instructor;

import com.goodmean.common.model.Clazz;
import com.goodmean.common.model.CourseStudentGrade;
import com.goodmean.common.model.Student;
import com.goodmean.common.model.Teacher;
import com.goodmean.common.model.base.BaseClazz;
import com.goodmean.student.StudentService;
import com.goodmean.teacher.admin.ClazzCourseService;
import com.goodmean.teacher.admin.CourseStudentGradeService;
import com.goodmean.teacher.teacher.TeacherService;
import com.jfinal.plugin.activerecord.Page;

import java.util.List;

public class InstructorService {
    public static final InstructorService me = new InstructorService();
    private BaseClazz clazzDAO = new Clazz().dao();

    /**
     * 班级信息管理
     **/
    public List<Clazz> fingdClazz() {
        return clazzDAO.find("SELECT * FROM clazz");
    }

    /**
     * 查询所管理的班级信息
     **/
    public List<Clazz> findByID(String id) {
        Integer instructorID = Integer.valueOf(id);
        return clazzDAO.find("SELECT * FROM clazz where teacher_id = ?", id);
    }

    /**
     * 个人信息管理
     **/
    public Teacher findByid(String id) {
        Integer teacher_id = Integer.valueOf(id);
        return TeacherService.me.findById(teacher_id);
    }

    /**
     * 学生成绩管理
     * 保存成绩
     **/
    public boolean saveStudentGrade(Integer grade , CourseStudentGrade csg) {
        boolean judge = false ;
        if (grade != null) {
            try {
                if (CourseStudentGradeService.me.findByStudentIdCourseId(csg.getStudentId(), csg.getCourseId()) == null) {
                    csg.save();
                } else {
                    csg.update();
                }
                judge = true;
            } catch (NullPointerException e) {
                judge = false;
            }
        }
        return judge;
    }
}
